// fetch js

import React, {
    Component
} from 'react';


export default class FetchRequest extends Component {

    //定义接收请求地址，当然也可以添加请求参数
    //parames 尽量是{'key1':'value1'，'key2':'value2'}
    //static request(url,parames,callBackSuccess,callBackError){


    //GET reqeust
    static async fetchGET(url, loadCallBack) {
      return   this.request(url, {
            method: 'GET',
            header: {
                'Access-Control-Allow-Origin': '*'
            }
        }, loadCallBack);

    }

    //POST reqeust
    static async fetchPOST(url, parames, loadCallBack) {
       
        return this.request(url, {
            method: 'POST',
            header: {
                'Accept': 'application/json',
                'Content-Type': 'application/json'
            },
            body:JSON.stringify(parames) 
        }, loadCallBack);
    }


    static async request(url, bodyObj, loadCallBack) {
        console.log(bodyObj);
        const urlPrefix = 'http://www.genetuan.com/cms/';
     
        // const urlPrefix=
        // //请求发送中回调,可以加一些loading效果  
        typeof (loadCallBack) == 'function' ? loadCallBack(): null;
        return fetch(urlPrefix + url, bodyObj);
    }
}